<template>
	<view>
		<!-- 顶部导航 -->
		<fa-navbar title="余额变动记录" :border-bottom="false"></fa-navbar>
		
		<view class="py-30">
			<view class="px-30 py-30 u-border-bottom" style="background: #fff;" v-for="(item,index) in list" :key="index">
				<view class="fr-ac-jsb">
					<view class="fs-30 bold flex-1">
						{{item.memo}}
					</view>
					
				</view>
				<view class="fr-ac-jsb gap-20">
					<view class="gray-9 fs-24 mt-16">
						余额：{{item.after}}
					</view>
					<view class="" :style="{
						'color': item.money>0?'red':'green'
					}">
						{{item.money>0?'+':''}}{{priceConversion(item.money)}}
					</view>
				</view>
				
			</view>
		</view>
		
	</view>
</template>

<script>
export default {
	onLoad() {
	},
	onShow() {
		
	},
	data() {
		return {
			id: '',
			
			name: '',
			card_num: '',
			bank: '',
			deposit: '',
			
			type: 'edit',
			
			
			page: 1,
			limit: 10,
			last_limit: 10,
			list: []
		};
	},
	onLoad() {
		this.getData()
	},
	onReachBottom() {
		if(this.limit == this.last_limit){
			this.page ++
			this.getData()
		}else{
			uni.showToast({
				title: '暂无更多',
				icon: 'none'
			})
		}
	},
	methods: {
		priceConversion(price) {
			price = Number(price)
			return (price).toFixed(2)
		},
		
		async getData(){
			let res = await this.$api.user_money_log({
				page: this.page,
				limit: this.limit
			});
			this.last_limit = res.data.list.length
			if(this.page == 1){
				this.list = res.data.list
			}else{
				this.list = this.list.concat(res.data.list)
			}
		},
		
		async submit(){
			if(this.name === ''){
				return this.$u.toast('请填写公司码')
			}
			if(this.card_num === ''){
				return this.$u.toast('请填写卡号')
			}
			
			let res = await this.$api.use_card({
				company_code: this.name,
				card_no: this.card_num
			});
			if (!res.code) {
				this.$u.toast(res.msg);
				return;
			}
			uni.showModal({
				title: '兑换成功！',
				showCancel: false
			})
		},
	},
	
};
</script>

<style lang="scss">
page {
	background-color: #f4f6f8;
}
</style>
<style lang="scss" scoped>
.gray-9{
	color: #999;
}
</style>
